package cn.e2win.biz.ds;

import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import cn.e2win.base.entity.SysLabel;
import cn.e2win.base.json.vo.Pager;
import cn.e2win.base.json.vo.Result;
import cn.e2win.biz.activity.ActivityService;
import cn.e2win.biz.base.BaseService;
import cn.e2win.biz.base.CommonService;
import cn.e2win.biz.cyzj.CyzjService;
import cn.e2win.biz.dbo.DsEmp;
import cn.e2win.biz.util.StringUtils;


@Controller
@Scope("request")
@RequestMapping("/m")
public class DsControllerM extends DsController {

	@Autowired
	private DsService dsService;
	@Autowired
	private CommonService commonService;
	@Autowired
	private CyzjService cyzjService;
	@Autowired
	private ActivityService activityService;

	@Override
	public BaseService initService() {
		return dsService;
	}


	@RequestMapping("dsMain")
	public String dsMain(HttpServletRequest request,@ModelAttribute DsEmp dsEmp, ModelMap modelMap){
		pager.getScMap().put("approveStatus", "APPROVED");
		dsService.pagerDs(pager);
		modelMap.put("pager", pager);

		String clazz = DsEmp.class.getSimpleName();
		List<SysLabel> allLabelIndustryList = commonService.getSysLabelList(clazz,"labelIndustry");
		List<SysLabel> allLabelFocusOnList = commonService.getSysLabelList(clazz,"labelFocusOn");
		List<SysLabel> allLabelHelpForList = commonService.getSysLabelList(clazz,"labelHelpFor");
		modelMap.put("allLabelIndustryList", allLabelIndustryList);
		modelMap.put("allLabelFocusOnList", allLabelFocusOnList);
		modelMap.put("allLabelHelpForList", allLabelHelpForList);

		return "m/dsMain";
	}

	@RequestMapping("editSelfInfoDsEmp")
	@ResponseBody
	public Result editSelfInfoDsEmp(HttpServletRequest request, @ModelAttribute DsEmp obj, ModelMap modelMap){
		Result r =null;
		r = super.editSelfInfoDsEmp(request,obj,modelMap);
		return r;
	}

	@RequestMapping("dsPagerM")
	@ResponseBody
	public Pager dsPagerM(HttpServletRequest request, ModelMap modelMap){
		String pageNum = request.getParameter("pageNum");
		if(StringUtils.isEmpty(pageNum)){
		
		}else{
			pager.setPageNum(Integer.parseInt(pageNum));
		}
		pager.getScMap().put("approveStatus", "APPROVED");
		super.dsPager(request, modelMap);
		//dsService.pagerDs(pager);
		return pager;
	}

	@RequestMapping("/dsDetail")
	public String dsDetail(HttpServletRequest request, @RequestParam("id")Integer id,
							 ModelMap modelMap) {
		DsEmp empty = new DsEmp(id);
		String clazz = DsEmp.class.getSimpleName();
		Map<String, Object> obj = dsService.getEntity(empty);

		modelMap.addAttribute("dsEmp",obj);
		
		/*
		DsEmp dsEmp = (DsEmp) dsService.getEntity(DsEmp.class,id);
		modelMap.addAttribute("dsEmp",dsEmp);
		List<SysLabel> labelIndustryList = commonService.getSysLabelList(dsEmp,"labelIndustry");
		List<SysLabel> labelFocusOnList = commonService.getSysLabelList(dsEmp,"labelFocusOn");
		List<SysLabel> labelHelpForList = commonService.getSysLabelList(dsEmp,"labelHelpFor");
		modelMap.put("labelIndustryList", labelIndustryList);
		modelMap.put("labelFocusOnList", labelFocusOnList);
		modelMap.put("labelHelpForList", labelHelpForList);
*/
		Pager cyzjPager = new Pager();
		cyzjPager.getScMap().put("dsEmpIds_I",id+"");
		cyzjPager.getScMap().put("activeStatusInt", "1");
		cyzjService.pagerDsRelatedCyzj(cyzjPager);
		modelMap.put("cyzjPager",cyzjPager);
		
		Pager activityPager = new Pager();
		activityPager.getScMap().put("dsEmpIds_L",id+"");
		activityPager.getScMap().put("activeStatusInt", "1");
		activityService.pagerActivity(activityPager);
		modelMap.put("activityPager",activityPager);


		return "/m/dsDetail";
	}


	@RequestMapping("dsManage")
	public String dsManage(HttpServletRequest request, ModelMap modelMap){
		/*pager.getScMap().put("approveStatus", "APPROVED");
		dsService.pagerDs(pager);
		modelMap.put("pager", pager);*/
		System.err.println("todo===" + todo);
		super.dsPager(request, modelMap);

		return "m/dsManage";
	}

	@RequestMapping("dsManageDetail")
	public String dsManageDetail(HttpServletRequest request,@RequestParam(value = "id",required = false) Integer id, ModelMap modelMap){
//		pager.getScMap().put("approveStatus", "APPROVED");
		DsEmp dsEmp = (DsEmp) dsService.getEntity(DsEmp.class,id);
		modelMap.addAttribute("dsEmp",dsEmp);
		return "m/dsManageDetail";
	}

}
